<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <title>社交网站 - 多样式滚动刷新提示</title>
  <!-- Bootstrap 5 CSS -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css">
  
  <style>
    /* 基础样式 */
    body {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
      background-color: #f8fafc;
      padding-top: 56px;
      margin: 0;
      overflow-x: hidden;
    }
    
    .container {
      max-width: 540px;
      margin: 0 auto;
      padding: 0 15px;
    }
    
    /* 顶部导航 */
    .main-header {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      height: 56px;
      background-color: white;
      box-shadow: 0 2px 5px rgba(0,0,0,0.05);
      z-index: 1000;
      display: flex;
      align-items: center;
      padding: 0 15px;
    }
    
    .logo {
      font-size: 20px;
      font-weight: 700;
      color: #0d6efd;
      text-decoration: none;
      display: flex;
      align-items: center;
      gap: 8px;
    }
    
    .header-actions {
      margin-left: auto;
      display: flex;
      align-items: center;
      gap: 15px;
    }
    
    .header-btn {
      width: 36px;
      height: 36px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      background: none;
      border: none;
      color: #6c757d;
      font-size: 18px;
      cursor: pointer;
    }
    
    /* 内容区域 */
    .content {
      padding: 15px 0;
      min-height: 150vh; /* 确保可以滚动 */
    }
    
    .card {
      background-color: white;
      border-radius: 12px;
      padding: 15px;
      margin-bottom: 15px;
      box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    }
    
    .card h3 {
      margin-top: 0;
      font-size: 18px;
    }
    
    /* 刷新提示容器 */
    .refresh-indicator {
      height: 50px;
      display: flex;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      transition: all 0.3s;
    }
    
    /* 刷新提示内容 */
    .refresh-content {
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 14px;
      transition: transform 0.3s;
    }
    
    /* 加载动画 */
    .spinner {
      width: 20px;
      height: 20px;
      border-radius: 50%;
      border: 2px solid;
      border-top-color: transparent;
      animation: spin 1s linear infinite;
      opacity: 0;
      transition: opacity 0.3s;
    }
    
    .refreshing .spinner {
      opacity: 1;
    }
    
    @keyframes spin {
      to { transform: rotate(360deg); }
    }
    
    /* 切换控制器 */
    .switcher {
      position: fixed;
      top: 20px;
      right: 20px;
      z-index: 1001;
      background-color: white;
      border-radius: 8px;
      box-shadow: 0 2px 10px rgba(0,0,0,0.1);
      padding: 10px;
      border: 1px solid #e9ecef;
    }
    
    .switch-label {
      font-size: 13px;
      margin-bottom: 8px;
      display: block;
      font-weight: 500;
    }
    
    .style-switch {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
    }
    
    .style-btn {
      padding: 5px 10px;
      border-radius: 4px;
      font-size: 12px;
      border: 1px solid #e9ecef;
      background: white;
      cursor: pointer;
    }
    
    .style-btn.active {
      background-color: #0d6efd;
      color: white;
      border-color: #0d6efd;
    }
    
    /* 提示框 */
    .toast {
      position: fixed;
      top: 70px;
      left: 50%;
      transform: translateX(-50%);
      background-color: rgba(0,0,0,0.8);
      color: white;
      border-radius: 8px;
      padding: 10px 15px;
      font-size: 14px;
      z-index: 10000;
      display: none;
    }
    
    /* 样式1 - 经典风格 */
    .style-1 .refresh-content {
      color: #6c757d;
    }
    
    .style-1 .spinner {
      border-color: #6c757d;
    }
    
    .style-1 .refreshed .refresh-content {
      color: #28a745;
    }
    
    /* 样式2 - 简洁风格 */
    .style-2 .refresh-content {
      color: #0d6efd;
    }
    
    .style-2 .spinner {
      border-color: #0d6efd;
    }
    
    .style-2 .refresh-indicator {
      height: 40px;
    }
    
    .style-2 .refreshed .refresh-content {
      color: #0d6efd;
    }
    
    /* 样式3 - 深色风格 */
    .style-3 {
      background-color: #1e293b;
    }
    
    .style-3 .card {
      background-color: #0f172a;
      color: #f8fafc;
    }
    
    .style-3 .main-header {
      background-color: #0f172a;
    }
    
    .style-3 .logo {
      color: #93c5fd;
    }
    
    .style-3 .header-btn {
      color: #94a3b8;
    }
    
    .style-3 .refresh-content {
      color: #94a3b8;
    }
    
    .style-3 .spinner {
      border-color: #94a3b8;
    }
    
    .style-3 .refreshed .refresh-content {
      color: #93c5fd;
    }
    
    /* 样式4 - 强调风格 */
    .style-4 .refresh-indicator {
      background-color: #f8f9fa;
      border-radius: 8px;
      margin: 0 15px;
    }
    
    .style-4 .refresh-content {
      color: #dc3545;
      font-weight: 500;
    }
    
    .style-4 .spinner {
      border-color: #dc3545;
    }
    
    .style-4 .refreshed .refresh-content {
      color: #28a745;
    }
    
    /* 样式5 - 图标风格 */
    .style-5 .refresh-content span {
      display: none;
    }
    
    .style-5 .refresh-content {
      color: #6c757d;
    }
    
    .style-5 .spinner {
      border-color: #6c757d;
    }
    
    .style-5 .refreshed .refresh-content {
      color: #28a745;
    }
  </style>
</head>
<body class="style-1">
  <!-- 切换控制器 -->
  <div class="switcher">
    <span class="switch-label">刷新样式</span>
    <div class="style-switch">
      <button class="style-btn active" data-style="1">经典风格</button>
      <button class="style-btn" data-style="2">简洁风格</button>
      <button class="style-btn" data-style="3">深色风格</button>
      <button class="style-btn" data-style="4">强调风格</button>
      <button class="style-btn" data-style="5">图标风格</button>
    </div>
  </div>
  
  <!-- 顶部导航 -->
  <header class="main-header">
    <a href="#" class="logo">
      <i class="fa fa-connectdevelop"></i>
      <span>社交圈</span>
    </a>
    
    <div class="header-actions">
      <button class="header-btn">
        <i class="fa fa-search"></i>
      </button>
      <button class="header-btn">
        <i class="fa fa-bell-o"></i>
      </button>
    </div>
  </header>
  
  <div class="container">
    <!-- 刷新提示区域 -->
    <div class="refresh-indicator" id="refreshIndicator">
      <div class="refresh-content" id="refreshContent">
        <div class="spinner" id="spinner"></div>
        <span id="refreshText">下拉可以刷新</span>
      </div>
    </div>
    
    <!-- 内容区域 -->
    <div class="content" id="content">
      <div class="card">
        <h3>推荐关注</h3>
        <p>根据您的兴趣，为您推荐了以下用户，点击关注即可获取他们的最新动态。</p>
      </div>
      
      <div class="card">
        <h3>热门话题</h3>
        <p>#夏日旅行 #美食分享 #电影推荐 #健身打卡 #职场技巧</p>
      </div>
      
      <div class="card">
        <h3>最新活动</h3>
        <p>「城市露营派对」将于6月15日举行，点击报名参与，认识更多新朋友！</p>
      </div>
      
      <div class="card">
        <h3>精选内容</h3>
        <p>这是一篇关于旅行摄影技巧的精选文章，作者分享了如何在旅途中拍出令人惊艳的照片。</p>
      </div>
      
      <div class="card">
        <h3>系统通知</h3>
        <p>新功能"圈子"已上线，您可以创建专属兴趣圈子，邀请好友加入讨论。</p>
      </div>
    </div>
  </div>
  
  <!-- 提示框 -->
  <div class="toast" id="toast">操作成功</div>
  
  <!-- Bootstrap JS -->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
  
  <script>
    // 获取元素
    const styleBtns = document.querySelectorAll('.style-btn');
    const refreshIndicator = document.getElementById('refreshIndicator');
    const refreshContent = document.getElementById('refreshContent');
    const refreshText = document.getElementById('refreshText');
    const spinner = document.getElementById('spinner');
    const content = document.getElementById('content');
    const toast = document.getElementById('toast');
    
    // 滚动刷新相关变量
    let startY = 0;
    let currentY = 0;
    let isDragging = false;
    let isRefreshing = false;
    const threshold = 60; // 触发刷新的阈值
    
    // 切换刷新样式
    styleBtns.forEach(btn => {
      btn.addEventListener('click', function() {
        // 移除所有活跃状态
        styleBtns.forEach(b => b.classList.remove('active'));
        document.body.className = '';
        
        // 添加当前样式
        this.classList.add('active');
        const style = this.getAttribute('data-style');
        document.body.classList.add(`style-${style}`);
        
        showToast(`已切换到${this.textContent}`);
      });
    });
    
    // 触摸开始事件
    content.addEventListener('touchstart', (e) => {
      if (window.scrollY <= 0 && !isRefreshing) {
        startY = e.touches[0].clientY;
        isDragging = true;
      }
    }, { passive: true });
    
    // 触摸移动事件
    content.addEventListener('touchmove', (e) => {
      if (isDragging && !isRefreshing) {
        currentY = e.touches[0].clientY;
        const diff = currentY - startY;
        
        if (diff > 0) {
          // 阻止页面滚动
          e.preventDefault();
          
          // 调整刷新指示器高度
          const height = Math.min(diff, 100);
          refreshIndicator.style.height = `${height}px`;
          
          // 改变提示文本
          if (diff > threshold) {
            refreshText.textContent = '松开刷新';
          } else {
            refreshText.textContent = '下拉可以刷新';
          }
        }
      }
    }, { passive: false });
    
    // 触摸结束事件
    content.addEventListener('touchend', () => {
      if (isDragging && !isRefreshing) {
        const diff = currentY - startY;
        
        if (diff > threshold) {
          // 触发刷新
          startRefresh();
        } else {
          // 恢复原状
          resetRefresh();
        }
        
        isDragging = false;
      }
    }, { passive: true });
    
    // 鼠标模拟触摸事件（用于桌面调试）
    content.addEventListener('mousedown', (e) => {
      if (window.scrollY <= 0 && !isRefreshing) {
        startY = e.clientY;
        isDragging = true;
      }
    });
    
    content.addEventListener('mousemove', (e) => {
      if (isDragging && !isRefreshing) {
        currentY = e.clientY;
        const diff = currentY - startY;
        
        if (diff > 0) {
          // 调整刷新指示器高度
          const height = Math.min(diff, 100);
          refreshIndicator.style.height = `${height}px`;
          
          // 改变提示文本
          if (diff > threshold) {
            refreshText.textContent = '松开刷新';
          } else {
            refreshText.textContent = '下拉可以刷新';
          }
        }
      }
    });
    
    content.addEventListener('mouseup', () => {
      if (isDragging && !isRefreshing) {
        const diff = currentY - startY;
        
        if (diff > threshold) {
          // 触发刷新
          startRefresh();
        } else {
          // 恢复原状
          resetRefresh();
        }
        
        isDragging = false;
      }
    });
    
    // 开始刷新
    function startRefresh() {
      isRefreshing = true;
      refreshIndicator.classList.add('refreshing');
      refreshIndicator.style.height = '50px';
      refreshText.textContent = '正在刷新...';
      
      // 模拟刷新过程
      setTimeout(() => {
        completeRefresh();
      }, 1500);
    }
    
    // 完成刷新
    function completeRefresh() {
      refreshIndicator.classList.remove('refreshing');
      refreshIndicator.classList.add('refreshed');
      refreshText.textContent = '刷新成功';
      
      // 添加新内容
      addNewContent();
      
      // 延迟后恢复原状
      setTimeout(() => {
        resetRefresh();
        refreshIndicator.classList.remove('refreshed');
      }, 1000);
    }
    
    // 重置刷新状态
    function resetRefresh() {
      isRefreshing = false;
      refreshIndicator.style.height = '50px';
      refreshText.textContent = '下拉可以刷新';
    }
    
    // 添加新内容
    function addNewContent() {
      const newCard = document.createElement('div');
      newCard.className = 'card';
      newCard.innerHTML = `
        <h3>新推荐内容</h3>
        <p>刚刚更新的内容：${new Date().toLocaleTimeString()} 新增了3篇热门文章和2个活动</p>
      `;
      
      // 将新内容添加到最前面
      const firstCard = document.querySelector('.card');
      content.insertBefore(newCard, firstCard);
      
      showToast('已更新最新内容');
    }
    
    // 显示提示
    function showToast(message) {
      toast.textContent = message;
      toast.style.display = 'block';
      
      setTimeout(() => {
        toast.style.display = 'none';
      }, 2000);
    }
    
    // 头部按钮事件
    document.querySelectorAll('.header-btn').forEach(btn => {
      btn.addEventListener('click', function() {
        const icon = this.querySelector('i');
        if (icon.classList.contains('fa-search')) {
          showToast('打开搜索');
        } else if (icon.classList.contains('fa-bell-o')) {
          showToast('查看通知');
        }
      });
    });
  </script>
</body>
</html>
